<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./OL_SDK/include-openlayers-local.js"></script>
    <script src="./libs/gaode.js"></script>
    <script src="https://lib.baomitu.com/jquery/2.2.4/jquery.js"></script>
    <script src="https://lib.baomitu.com/Turf.js/latest/turf.min.js"></script>
</head>

<body>
    <div id="map">
    </div>
    <script>
        var map = new ol.Map({
            target: "map",
            layers: [gaode],
            view: new ol.View({
                projection: 'EPSG:4326',
                center: [114.30, 30.50],
                zoom: 4
            })
        })
        let key = 'db774d5285ed8eb97c1d816f8e671c94'
        var url = `https://restapi.amap.com/v3/ip?key=${key}`;
        /* 调高德api
        1、获取城市的中心点  --设置点要素执行飞行视角
        2、获取邮编-geojson
         */
        $.ajax({
            url,
            success: res => {
                var { adcode, rectangle } = res;
                var positions = rectangle.split(";")
                var arr = [];
                positions.forEach(item => {
                    arr.push(item.split(","))
                })
                /* turf */
                var point1 = turf.point(arr[0]);
                var point2 = turf.point(arr[1]);

                var midpoint = turf.midpoint(point1, point2);
                var center = midpoint.geometry.coordinates;
                console.log(center);
            }
        })
    </script>
</body>

</html>